<?php
class CustomerController extends ModuleController {

    
    private $current_step;
    public function onCreatePage() {
        $args = $this->getArgs();
        $this->load->library('', 'customer');
        $this->load->library('FormFactories', 'customer');
        $this->load->library('FormDecorators', 'customer');
        $this->load->library('StepStrategies', 'customer');
        
        $this->getFormManager()->addHandler($this);

        if (isset($args[2]) && preg_match('/^step(\d+)$/ui', $args[2], $res)) {
            $this->current_step = $res[1];
        } elseif (isset($args[1]) && $args[1] == 'add')
            $this->current_step = 1;
        elseif ($this->current_step == null)
            $this->current_step = 1;
    }
    /**
     * @blocks: navigation, loginblock, vklogin
     */
    public function step_manager() {
       $args = $this->getArgs();
       $this->output($this->view->getCustomer_stepper(array('steps_links' => TaskFormHelper::$steps_links , 'current_step' => $this->current_step)));

       $form_facade = $this->getFormFacade();
       $form_html = $form_facade->buildForm();
    
       $this->output($form_html);
        return OK;
    }

    public function validate_post_create_task(&$data, &$scope, &$manager) {
       $form_facade = $this->getFormFacade();
       return $form_facade->validate_form($data, $scope);
    }

    public function submit_post_create_task($data, $scope, $manager) {
       $form_facade = $this->getFormFacade();
       $form_facade->submit_form($data, $scope);
    }

    private function getFormFacade() {
       $form_facade = new TaskFormFacade($this->getContext());
       $step_strategy_factory = new StepStrategyFactory();
       $current_step_strategy = $step_strategy_factory->createStepStrategy($this->current_step);
       $form_facade->setStepStrategy($current_step_strategy);
       return $form_facade;
    }
    
//    public function validate_post_step3_form(&$data, &$scope, &$manager) {
//       $form_facade = new TaskFormFacade($this->getContext());
//       $step_strategy_factory = new StepStrategyFactory();
//       $current_step_strategy = $step_strategy_factory->createStepStrategy(3);
//       $form_facade->setStepStrategy($current_step_strategy);
//       return $form_facade->validate_form($data, $scope);
//    }
//
//    public function submit_post_step3_form($data, &$scope, $manager) {
//       $form_facade = new TaskFormFacade($this->getContext());
//       $step_strategy_factory = new StepStrategyFactory();
//       $current_step_strategy = $step_strategy_factory->createStepStrategy(3);
//       $form_facade->setStepStrategy($current_step_strategy);
//       $form_facade->submit_form($data, $scope);
//    }
//
//    public function validate_post_step4_form(&$data, &$scope, &$manager) {
//       $form_facade = new TaskFormFacade($this->getContext());
//       $step_strategy_factory = new StepStrategyFactory();
//       $current_step_strategy = $step_strategy_factory->createStepStrategy(4);
//       $form_facade->setStepStrategy($current_step_strategy);
//       return $form_facade->validate_form($data, $scope);
//    }
//
//    public function submit_post_step4_form($data, &$scope, $manager) {
//       $form_facade = new TaskFormFacade($this->getContext());
//       $step_strategy_factory = new StepStrategyFactory();
//       $current_step_strategy = $step_strategy_factory->createStepStrategy(4);
//       $form_facade->setStepStrategy($current_step_strategy);
//       $form_facade->submit_form($data, $scope);
//    }
}

?>
